<?php
require_once("vcl/vcl.inc.php");
require_once("config_msdb.php");
//Includes
use_unit("components4phpfull/jtpanel.inc.php");
use_unit("components4phpfull/jtrawoutput.inc.php");
use_unit("components4phpfull/jtheadercode.inc.php");
use_unit("styles.inc.php");
use_unit("components4phpfull/jtiframe.inc.php");
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("comctrls.inc.php");
use_unit("buttons.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtlabel.inc.php");
use_unit("components4phpfull/jtpdodatabase.inc.php");
use_unit("components4phpfull/jtlookupcombobox.inc.php");
use_unit("db.inc.php");
use_unit("dbtables.inc.php");
use_unit("components4phpfull/jtbevel.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class iclientpage extends Page
{
       public $save2 = null;
       public $back2 = null;
       public $btnSaveCont = null;
       public $Image3 = null;
       public $errorlistb = null;
       public $JTDivWindow2 = null;
       public $valerror = null;
       public $JTJavaScript5 = null;
       public $Label43 = null;
       public $usernamesession = null;
       public $JTJavaScript4 = null;
       public $cancontbtn = null;
       public $loadcontimg = null;
       public $addcontbtn = null;
       public $Econtemail1 = null;
       public $Label20 = null;
       public $Econtfax1 = null;
       public $Label30 = null;
       public $contmun = null;
       public $Label42 = null;
       public $contprov = null;
       public $Label41 = null;
       public $contregion = null;
       public $Label27 = null;
       public $contbuild = null;
       public $Label26 = null;
       public $Econtmob1 = null;
       public $Label12 = null;
       public $Label23 = null;
       public $Econtphone1 = null;
       public $cmbcontyear1 = null;
       public $cmbcontday1 = null;
       public $cmbcontmonth1 = null;
       public $Label9 = null;
       public $Edesignation1 = null;
       public $Label6 = null;
       public $Econtlname1 = null;
       public $Label24 = null;
       public $Econtmname1 = null;
       public $Label22 = null;
       public $Label7 = null;
       public $Label28 = null;
       public $Econtadd1 = null;
       public $Econtfname1 = null;
       public $editMun4 = null;
       public $editProv4 = null;
       public $Label25 = null;
       public $sabuild = null;
       public $sanewbtn = null;
       public $saexistbtn = null;
       public $addnewbtn = null;
       public $JTIFrame1 = null;
       public $sacodeexist = null;
       public $editMun3 = null;
       public $editProv3 = null;
       public $samun = null;
       public $saprov = null;
       public $saregion = null;
       public $Label48 = null;
       public $Label21 = null;
       public $reglbl = null;
       public $compwebsite = null;
       public $Label47 = null;
       public $Label46 = null;
       public $Ecompbldg = null;
       public $Einbldg = null;
       public $Label40 = null;
       public $Ecnumhid = null;
       public $sacodehid = null;
       public $sagenbtn = null;
       public $Label39 = null;
       public $sacode = null;
       public $saflag = null;
       public $lblselsa = null;
       public $loadinglbl = null;
       public $JTJavaScript3 = null;
       public $saok = null;
       public $said = null;
       public $subagentcmb = null;
       public $JTDivWindow1 = null;
       public $Label29 = null;
       public $JTJavaScript2 = null;
       public $lblindi = null;
       public $lblcorp = null;
       public $editMun2 = null;
       public $editProv2 = null;
       public $editMun = null;
       public $editProv = null;
       public $JTJavaScript1 = null;
       public $btnGenCnum = null;
       public $Ecnum = null;
       public $Ecompanyadd = null;
       public $Esubemail1 = null;
       public $Esubfax1 = null;
       public $Esubphone1 = null;
       public $Esubmobile1 = null;
       public $Esubadd1 = null;
       public $Esublname1 = null;
       public $Esubmname1 = null;
       public $Esubfname1 = null;
       public $cmbsubyear1 = null;
       public $cmbsubday1 = null;
       public $cmbsubmonth1 = null;
       public $Label63 = null;
       public $Label62 = null;
       public $Label58 = null;
       public $Label57 = null;
       public $Label56 = null;
       public $Label55 = null;
       public $Label54 = null;
       public $Label53 = null;
       public $Label52 = null;
       public $cmbyear = null;
       public $cmbday = null;
       public $cmbMonth = null;
       public $Image6 = null;
       public $Epovinceid2 = null;
       public $Eregionid2 = null;
       public $cmbMunicipal2 = null;
       public $cmbProvince2 = null;
       public $cmbRegion2 = null;
       public $Label38 = null;
       public $Label37 = null;
       public $Label36 = null;
       public $Emiddlename = null;
       public $Efirstname = null;
       public $Elastname = null;
       public $Label35 = null;
       public $Label31 = null;
       public $Epovinceid = null;
       public $Eregionid = null;
       public $Label34 = null;
       public $cmbMunicipal = null;
       public $Label33 = null;
       public $cmbProvince = null;
       public $Label32 = null;
       public $cmbRegion = null;
       public $Image5 = null;
       public $Ecompname = null;
       public $lblclienttype = null;
       public $lblC = null;
       public $eproduct = null;
       public $email = null;
       public $ephone = null;
       public $efax = null;
       public $ebusiness = null;
       public $Einemail = null;
       public $Einmobile = null;
       public $Einnum = null;
       public $Einfaxnum = null;
       public $Einadd = null;
       public $cmbindust = null;
       public $cmbmothercom = null;
       public $Eclientnum = null;
       public $Image4 = null;
       public $Label5 = null;
       public $Label2 = null;
       public $Label10 = null;
       public $Label19 = null;
       public $Label18 = null;
       public $Label17 = null;
       public $Label16 = null;
       public $Label15 = null;
       public $Label14 = null;
       public $Label13 = null;
       public $Label8 = null;
       public $Image2 = null;
       public $Image1 = null;
       public $JTSiteTheme1 = null;
       public $Label66 = null;
       public $lblstatus = null;
       public $Label11 = null;
       public $Essrcinum = null;
       public $Label4 = null;
       public $Eclientname = null;
       public $Label3 = null;
       public $Eclient_num = null;
       public $Label1 = null;

       function back2JSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['back2'].src = 'images/backsel.png';
       <?php

       }

       function back2JSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['back2'].src = 'images/back.png';
       <?php

       }

       function save2JSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['save2'].src = 'images/savesel.png';
       <?php

       }

       function save2JSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['save2'].src = 'images/save.png';
       <?php

       }

       function btnSaveContJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['btnSaveCont'].src = 'images/savesel.png';
       <?php

       }

       function btnSaveContJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['btnSaveCont'].src = 'images/save.png';
       <?php

       }

       function btnSaveContJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var ecnumval = document.getElementById('Ecnum').value;
       var sacodeval = document.getElementById('sacode').value;
       if(ecnumval == "")
       {
       validate("Ecnum","Generate Client No. First");
       //alert("Generate Client No. First");
       //document.getElementById('Ecnum').focus();
       //return false;
       }
       else if(sacodeval == "")
       {
       validate("sacode","Generate Sub-Agent No. First");
       //alert("Generate Sub-Agent No. First");
       //document.getElementById('sacode').focus();
       //return false;
       }
       <?php

       }


       function contmunJSChange($sender, $params)
       {

       ?>
       //Add your javascript code here
       var sel4 = document.getElementById('contmun');
       var munSel4 = sel4.options[sel4.selectedIndex].value;
       document.getElementById('editMun4').value = munSel4;
       <?php

       }

       function contprovJSChange($sender, $params)
       {

       ?>
       //Add your javascript code here
       var sel4 = document.getElementById('contprov');
       var provSel4 = sel4.options[sel4.selectedIndex].value;
       AjaxFunction(provSel4,'provdd.php','contmun');
       document.getElementById('editProv4').value = provSel4;
       <?php

       }

       function contregionJSChange($sender, $params)
       {

       ?>
       //Add your javascript code here
       var sel4 = document.getElementById('contregion');
       var regionSel4 = sel4.options[sel4.selectedIndex].value;
       AjaxFunction(regionSel4,'dd.php','contprov');
       <?php

       }

       function Image5JSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['Image5'].src = 'images/backsel.png';
       <?php

       }

       function Image5JSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['Image5'].src = 'images/back.png';
       <?php

       }

       function cancontbtnJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('addcontbtn').style.display = 'none';
       document.getElementById('addcontbtn').style.visibility = 'hidden';
       document.getElementById('cancontbtn').style.display = 'none';
       document.getElementById('cancontbtn').style.visibility = 'hidden';
       document.getElementById( "JTDivWindow3" ).Hide();

       <?php

       }

       function iclientpageJSLoad($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('loadcontimg').style.display = 'none';
       document.getElementById('loadcontimg').style.visibility = 'hidden';
       document.getElementById('loadcontimg').style.display = 'none';
       document.getElementById('loadcontimg').style.visibility = 'hidden';
       <?php

       }

       function addcontbtnJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('addcontbtn').style.display = 'none';
       document.getElementById('addcontbtn').style.visibility = 'hidden';
       //document.getElementById('cancontbtn').style.display = 'none';
       //document.getElementById('cancontbtn').style.visibility = 'hidden';
       document.getElementById('loadcontimg').style.display = 'block';
       document.getElementById('loadcontimg').style.visibility = 'visible';
       var ecnum = document.getElementById('Ecnumhid').value;
       var econtfname = document.getElementById('Econtfname1').value;
       var econtmname = document.getElementById('Econtmname1').value;
       var econtlname = document.getElementById('Econtlname1').value;
       var cmbcontmonth = document.getElementById('cmbcontmonth1').options[document.getElementById('cmbcontmonth1').selectedIndex].value;
       var cmbcontday = document.getElementById('cmbcontday1').options[document.getElementById('cmbcontday1').selectedIndex].value;
       var cmbcontyear = document.getElementById('cmbcontyear1').options[document.getElementById('cmbcontyear1').selectedIndex].value;
       var econtmob = document.getElementById('Econtmob1').value;
       var econtemail = document.getElementById('Econtemail1').value;
       var edesignation = document.getElementById('Edesignation1').value;
       var econtadd = document.getElementById('Econtadd1').value;
       var econtphone = document.getElementById('Econtphone1').value;
       var econtfax = document.getElementById('Econtfax1').value;
       var usernamelogged = document.getElementById('usernamesession').value;
       var contbuild = document.getElementById('contbuild').value;
       var contregion = document.getElementById('contregion').options[document.getElementById('contregion').selectedIndex].value;
       var contprov = document.getElementById('contprov').options[document.getElementById('contprov').selectedIndex].value;
       var contmun = document.getElementById('contmun').options[document.getElementById('contmun').selectedIndex].value;
       var arr = new Array(econtfname,econtmname,econtlname,cmbcontmonth,cmbcontday,cmbcontyear,econtmob,econtemail,edesignation,econtadd,econtphone,econtfax);
       var arrname = new Array('econtfname','econtmname','econtlname','cmbcontmonth','cmbcontday','cmbcontyear','econtmob','econtemail','edesignation','econtadd','econtphone','econtfax');
       Ajaxsavecont(usernamelogged,econtfname,econtmname,econtlname,cmbcontmonth,cmbcontday,cmbcontyear,econtmob,econtemail,edesignation,econtadd,econtphone,econtfax,contbuild,contregion,contprov,contmun);
       <?php

       }


       function addnewbtnJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('Econtfname1').value = "";
       document.getElementById('Econtmname1').value = "";
       document.getElementById('Econtlname1').value = "";
       document.getElementById('cmbcontmonth1')[0].selected = 'selected';
       document.getElementById('cmbcontday1')[0].selected = 'selected';
       document.getElementById('cmbcontyear1')[0].selected = 'selected';
       document.getElementById('Econtmob1').value = "";
       document.getElementById('Econtemail1').value = "";
       document.getElementById('Edesignation1').value = "";
       document.getElementById('Econtadd1').value = "";
       document.getElementById('Econtphone1').value = "";
       document.getElementById('Econtfax1').value = "";
       document.getElementById('contbuild').value = "";
       document.getElementById('contregion').options[0].selected = true;
       for(j=document.getElementById('contprov').options.length-1;j>=0;j--)
       {
       document.getElementById('contprov').remove(j);
       }
       var objDropdown21 = document.getElementById('contprov');
       var objOption21 = new Option('-- Select Region First --','');
       objDropdown21.options[objDropdown21.length] = objOption21;
       for(j=document.getElementById('contmun').options.length-1;j>=0;j--)
       {
       document.getElementById('contmun').remove(j);
       }
       var objDropdown22 = document.getElementById('contmun');
       var objOption22 = new Option('-- Select Province First --','');
       objDropdown22.options[objDropdown22.length] = objOption22;
       document.getElementById( "JTDivWindow3" ).Show();
       document.getElementById('addcontbtn').style.display = 'block';
       document.getElementById('addcontbtn').style.visibility = 'visible';
       document.getElementById('cancontbtn').style.display = 'block';
       document.getElementById('cancontbtn').style.visibility = 'visible';
       document.getElementById('loadcontimg').style.display = 'none';
       document.getElementById('loadcontimg').style.visibility = 'hidden';
       <?php

       }


       function samunJSChange($sender, $params)
       {

       ?>
       //Add your javascript code here
       var sel3 = document.getElementById('samun');
       var munSel3 = sel3.options[sel3.selectedIndex].value;
       document.getElementById('editMun3').value = munSel3;
       <?php

       }

       function saprovJSChange($sender, $params)
       {

       ?>
       //Add your javascript code here
       //var sel3 = document.getElementById('saprov');
       //var provSel3 = sel3.options[sel3.selectedIndex].value;
       //AjaxFunction(provSel3,'provdd.php','samun');
       //document.getElementById('editProv3').value = provSel3;
       var sel3 = document.getElementById('saprov');
       var provSel3 = sel3.options[sel3.selectedIndex].value;
       AjaxFunction(provSel3,'provdd.php','samun');
       document.getElementById('editProv3').value = provSel3;
       <?php

       }

       function saregionJSChange($sender, $params)
       {

       ?>
       //Add your javascript code here
       var sel3 = document.getElementById('saregion');
       var regionSel3 = sel3.options[sel3.selectedIndex].value;
       AjaxFunction(regionSel3,'dd.php','saprov');
       <?php

       }



       function sagenbtnJSClick($sender, $params)
       {

       ?>
       document.getElementById('sacode').value = "Generating...";
       //Add your javascript code here
       AjaxFunction2('SA','cnumget.php','sacode','sacodehid');
       document.getElementById('sagenbtn').disabled = true;
       document.getElementById('sacode').disabled = true;
       <?php

       }


       function saexistJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['saexist'].src = "images/saexist.png";
       <?php

       }

       function saexistJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['saexist'].src = "images/saexisth.png";
       <?php

       }


       function sanewJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['sanew'].src = "images/sanew.png";
       <?php

       }

       function sanewJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['sanew'].src = "images/sanewh.png";
       <?php

       }


       function saexistJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById("loadinglbl").style.display = 'none';
       document.getElementById("lblselsa").style.display = 'block';
       document.getElementById("subagentcmb").style.display = 'block';
       document.getElementById("saok").style.display = 'block';
       document.getElementById( "JTDivWindow1" ).Show();
       <?php

       }

       function sanewJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var codeid = document.getElementById('sacodehid').value;
       document.getElementById('sacode').value = codeid;
       if(codeid)
       {
	   document.getElementById('sagenbtn').disabled = true;
       }
       else
       {
       document.getElementById('sagenbtn').disabled = false;
       }
       document.getElementById('Esubfname1').value = "";
       document.getElementById('Esubmname1').value = "";
       document.getElementById('Esublname1').value = "";
       document.getElementById('Esubadd1').value = "";
       document.getElementById('Esubphone1').value = "";
       document.getElementById('Esubmobile1').value = "";
       document.getElementById('Esubfax1').value = "";
       document.getElementById('Esubemail1').value = "";
       document.getElementById('sabuild').value = "";
       document.getElementById('cmbsubmonth1').options[0].selected = true;
       document.getElementById('cmbsubday1').options[0].selected = true;
       document.getElementById('cmbsubyear1').options[0].selected = true;
       document.getElementById('saregion').options[0].selected = true;
       for(j=document.getElementById('saprov').options.length-1;j>=0;j--)
       {
       document.getElementById('saprov').remove(j);
       }
       var objDropdown21 = document.getElementById('saprov');
       var objOption21 = new Option('-- Select Region First --','');
       objDropdown21.options[objDropdown21.length] = objOption21;
       for(j=document.getElementById('samun').options.length-1;j>=0;j--)
       {
       document.getElementById('samun').remove(j);
       }
       var objDropdown22 = document.getElementById('samun');
       var objOption22 = new Option('-- Select Province First --','');
       objDropdown22.options[objDropdown22.length] = objOption22;
       document.getElementById('saflag').value = "new";
       document.getElementById( "JTDivWindow1" ).Hide();
       <?php

       }

       function saokJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var selectedindex = document.getElementById('subagentcmb').selectedIndex;
       var selecteditem = document.getElementById('subagentcmb')[selectedindex].value;
       //document.getElementById('Edit1').value = selecteditem;
       document.getElementById('said').value = selecteditem;
       AjaxFunction4(selecteditem);

       <?php

       }

       function lblcorpJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['lblcorp'].src = "images/coradd.png";
       <?php

       }

       function lblcorpJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['lblcorp'].src = "images/coraddsel.png";
       <?php

       }




       function btnGenCnumJSClick($sender, $params)
       {

       ?>
       document.getElementById('Ecnum').value = "Generating...";
       AjaxFunction2('Individual','cnumget.php','Ecnum','Ecnumhid');
       document.getElementById('btnGenCnum').disabled = true;
       document.getElementById('Ecnum').disabled = true;
       <?php



       }
       function btnGenCnumJSClickAjax($sender, $params)
       {
       mssql_query("INSERT INTO client_inum_tbl (client_num) VALUES ('".$this->Eclient_num->Text."')") or die(mssql_error());
       $this->Ecnum->Text = $this->lblC->Caption.$this->Eclientnum->Text;
       $this->btnGenCnum->Enabled = false;
       }

       function regionOnChange($sender, $params)
       {
       ?>
       var sel = document.getElementById('cmbRegion');
       var regionSel = sel.options[sel.selectedIndex].value;
       AjaxFunction(regionSel,'dd.php','cmbProvince');
       <?php
       }

       function provOnChange($sender, $params)
       {
       ?>
       var sel = document.getElementById('cmbProvince');
       var provSel = sel.options[sel.selectedIndex].value;
       AjaxFunction(provSel,'provdd.php','cmbMunicipal');
       document.getElementById('editProv').value = provSel;
       <?php
       }
       function munOnChange($sender, $params)
       {
       ?>
       var sel = document.getElementById('cmbMunicipal');
       var munSel = sel.options[sel.selectedIndex].value;
       document.getElementById('editMun').value = munSel;
       <?php
       }
       function region2OnChange($sender, $params)
       {
       ?>
       var sel2 = document.getElementById('cmbRegion2');
       var regionSel2 = sel2.options[sel2.selectedIndex].value;
       AjaxFunction(regionSel2,'dd.php','cmbProvince2');
       <?php
       }

       function prov2OnChange($sender, $params)
       {
       ?>
       var sel2 = document.getElementById('cmbProvince2');
       var provSel2 = sel2.options[sel2.selectedIndex].value;
       AjaxFunction(provSel2,'provdd.php','cmbMunicipal2');
       document.getElementById('editProv2').value = provSel2;
       <?php
       }
       function mun2OnChange($sender, $params)
       {
       ?>
       var sel2 = document.getElementById('cmbMunicipal2');
       var munSel2 = sel2.options[sel2.selectedIndex].value;
       document.getElementById('editMun2').value = munSel2;
       <?php
       }




       function cmbProvince2Change($sender, $params)
       {
       $query = "SELECT * FROM province_tbl WHERE province = '".$this->cmbProvince2->Items[$this->cmbProvince2->ItemIndex]."'";
       $result = mssql_query($query);
       $num_rows = mssql_num_rows($result);
        if($num_rows > 0)
         {
          while($row = mssql_fetch_assoc($result))
           {
            $field = $row['id'];

            $this->Epovinceid2->Text = $field;
           }
         }

       $query = "SELECT * FROM municipality_tbl WHERE province_id = '".$this->Epovinceid2->Text."'";
       $result = mssql_query($query);
       $num_rows = mssql_num_rows($result);
        if($num_rows > 0)
         {
          $this->cmbMunicipal2->Clear();
          $this->cmbMunicipal2->AddItem("");
          while($row = mssql_fetch_assoc($result))
           {
            $field = $row['municipality'];

            $this->cmbMunicipal2->AddItem($field);
           }
         }
       }

       function cmbRegion2Change($sender, $params)
       {
       $query = "SELECT * FROM region_tbl WHERE region = '".$this->cmbRegion2->Items[$this->cmbRegion2->ItemIndex]."'";
       $result = mssql_query($query);
       $num_rows = mssql_num_rows($result);
        if($num_rows > 0)
        {
         while($row = mssql_fetch_assoc($result))
          {
            $field = $row['id'];

            $this->Eregionid2->Text = $field;
          }
        }

       $query = "SELECT * FROM province_tbl WHERE region_id = '".$this->Eregionid2->Text."'";
       $result = mssql_query($query);
       $num_rows = mssql_num_rows($result);
        if($num_rows > 0)
        {
         $this->cmbProvince2->Clear();
         $this->cmbProvince2->AddItem("");
         while($row = mssql_fetch_assoc($result))
          {
            $field = $row['province'];

            $this->cmbProvince2->AddItem($field);
          }
        }


       }

       function cmbProvinceChange($sender, $params)
       {
       $query = "SELECT * FROM province_tbl WHERE province = '".$this->cmbProvince->Items[$this->cmbProvince->ItemIndex]."'";
       $result = mssql_query($query);
       $num_rows = mssql_num_rows($result);
        if($num_rows > 0)
         {
          while($row = mssql_fetch_assoc($result))
           {
            $field = $row['id'];

            $this->Epovinceid->Text = $field;
           }
         }

       $query = "SELECT * FROM municipality_tbl WHERE province_id = '".$this->Epovinceid->Text."'";
       $result = mssql_query($query);
       $num_rows = mssql_num_rows($result);
        if($num_rows > 0)
         {
          $this->cmbMunicipal->Clear();
          $this->cmbMunicipal->AddItem("");
          while($row = mssql_fetch_assoc($result))
           {
            $field = $row['municipality'];

            $this->cmbMunicipal->AddItem($field);
           }
         }
       }

       function cmbRegionChange($sender, $params)
       {
       $query = "SELECT * FROM region_tbl WHERE region = '".$this->cmbRegion->Items[$this->cmbRegion->ItemIndex]."'";
       $result = mssql_query($query);
       $num_rows = mssql_num_rows($result);
        if($num_rows > 0)
        {
         while($row = mssql_fetch_assoc($result))
          {
            $field = $row['id'];

            $this->Eregionid->Text = $field;
          }
        }

       $query = "SELECT * FROM province_tbl WHERE region_id = '".$this->Eregionid->Text."'";
       $result = mssql_query($query);
       $num_rows = mssql_num_rows($result);
        if($num_rows > 0)
        {
         $this->cmbProvince->Clear();
         $this->cmbProvince->AddItem("");
         while($row = mssql_fetch_assoc($result))
          {
            $field = $row['province'];

            $this->cmbProvince->AddItem($field);
          }
        }

       }


       function btnAddcontClick($sender, $params)
       {
         $this->JTBevel1->Visible = true;
       }

       function btnSaveContClick($sender, $params)
       {
       //$serial = $this->lblC->Caption.$this->Eclient_num->Text;
       /*
       mssql_query("INSERT INTO client_inum_tbl (client_num)
                  VALUES ('".$this->Eclient_num->Text."')")
       or die (mssql_error());
       */
       $this->errorlistb->Clear();
       $this->valerror->Value = '0';
       if($this->Ecnumhid->Value == "")
       { $this->errorlistb->AddItem("Client No. not generated.","","");$this->valerror->Value = '1'; }
       //if($this->sacodehid->Value == "")
       //{ $this->errorlistb->AddItem("Sub-Agent No. not generated.","","");$this->valerror->Value = '1'; }
       if($this->Efirstname->Text == "")
       { $this->errorlistb->AddItem("Firstname required.","","");$this->valerror->Value = '1'; }
       if($this->Elastname->Text == "")
       { $this->errorlistb->AddItem("Lastname required.","","");$this->valerror->Value = '1'; }
       if($this->Einnum->Text == "")
       { $this->errorlistb->AddItem("Phone No. required.","","");$this->valerror->Value = '1'; }
	   if($this->Einadd->Text == "")
       { $this->errorlistb->AddItem("Address required.","","");$this->valerror->Value = '1'; }
	   //if($this->Einbldg->Text == "")
       //{ $this->errorlistb->AddItem("Building required.","","");$this->valerror->Value = '1'; }
	   if($this->cmbRegion->Items[$this->cmbRegion->ItemIndex] == "-- Select --")
       { $this->errorlistb->AddItem("Region required.","","");$this->valerror->Value = '1'; }
	   if($this->editProv->Value == "")
       { $this->errorlistb->AddItem("Province required.","","");$this->valerror->Value = '1'; }
	   if($this->editMun->Value == "")
       { $this->errorlistb->AddItem("Municipality required.","","");$this->valerror->Value = '1'; }


       if($this->valerror->Value == '1')
       {
       $this->Ecnum->Text = $this->Ecnumhid->Value;
       $this->sacode->Text = $this->sacodehid->Value;
	     $this->cmbProvince->AddItem($this->editProv->Value, "", $this->editProv->Value);
	     $this->cmbProvince->ItemIndex = $this->editProv->Value;
	     $this->cmbMunicipal->AddItem($this->editMun->Value, "", $this->editMun->Value);
       $this->cmbMunicipal->ItemIndex = $this->editMun->Value;
       $this->cmbProvince2->AddItem($this->editProv2->Value, "", $this->editProv2->Value);
	     $this->cmbProvince2->ItemIndex = $this->editProv2->Value;
       $this->cmbMunicipal2->AddItem($this->editMun2->Value, "", $this->editMun2->Value);
       $this->cmbMunicipal2->ItemIndex = $this->editMun2->Value;
       $this->saprov->AddItem($this->editProv3->Value, "", $this->editProv3->Value);
	     $this->saprov->ItemIndex = $this->editProv3->Value;
       $this->samun->AddItem($this->editMun3->Value, "", $this->editMun3->Value);
       $this->samun->ItemIndex = $this->editMun3->Value;
	     $this->JTDivWindow2->ShowWindow();
       }
       else if($this->valerror->Value == '0')
       {
       $usernamelogged = $_SESSION['username'];
       $subagentidget = '';
       $cnum = $this->lblC->Caption.$this->Eclientnum->Text;
        if($this->saflag->Value == 'new')
        {
        $subagentidget = $this->sacodehid->Value;
        }
        else if($this->saflag->Value == 'exist')
        {
        $subagentidget = $this->sacodeexist->Value;
        }
       mssql_query("INSERT INTO client_tbl(status,client_type,client_num,Fname,Lname,Mname,i_add,i_region,i_province
                   ,i_municipal,bday_month,bday_day,bday_year,i_phone,i_fax,i_mob,i_email,mother_comp,comp_add
                   ,region,province,municipal,business_type,industry,product,ofis_phone,fax_num,email,sub_agent_id,building,ecompbldg,compwebsite)
                  VALUES('".$this->lblstatus->Caption."','".$this->lblclienttype->Caption."','".$this->Ecnumhid->Value."'
                  ,'".$this->Efirstname->Text."','".$this->Elastname->Text."','".$this->Emiddlename->Text."'
                  ,'".$this->Einadd->Text."','".$this->cmbRegion->Items[$this->cmbRegion->ItemIndex]."'
                  ,'".$this->editProv->Value."'
                  ,'".$this->editMun->Value."'
                  ,'".$this->cmbMonth->Items[$this->cmbMonth->ItemIndex]."'
                  ,'".$this->cmbday->Items[$this->cmbday->ItemIndex]."'
                  ,'".$this->cmbyear->Items[$this->cmbyear->ItemIndex]."','".$this->Einnum->Text."'
                  ,'".$this->Einfaxnum->Text."','".$this->Einmobile->Text."','".$this->Einemail->Text."'
                  ,'".$this->Ecompname->Text."','".$this->Ecompanyadd->Text."'
                  ,'".$this->cmbRegion2->Items[$this->cmbRegion2->ItemIndex]."'
                  ,'".$this->editProv2->Value."'
                  ,'".$this->editMun2->Value."'
                  ,'".$this->ebusiness->Text."','".$this->cmbindust->Items[$this->cmbindust->ItemIndex]."'
                  ,'".$this->eproduct->Text."','".$this->ephone->Text."','".$this->efax->Text."','".$this->email->Text."','".$subagentidget."','".$this->Einbldg->Text."','".$this->Ecompbldg->Text."','".$this->compwebsite->Text."')")
       or die (mssql_error());
       $resulter = mssql_query("SELECT * FROM contact_tbl where client_num='".$usernamelogged."'") or die (mssql_error());
       while($rower = mssql_fetch_array($resulter))
       {
	     $qSave = "UPDATE contact_tbl SET client_num = '".$this->Ecnumhid->Value."' WHERE id = '".$rower['id']."'";
         $resSave = mssql_query($qSave) or die('Something went wrong: '.mssql_error());
       }
       /*
       if($this->Econtfname1->Text != '')
        {
         mssql_query("INSERT INTO contact_tbl(client_num,contact_fname,contact_mname,contact_lname,contactbday_month
                    ,contactbday_day,contactbday_year,contact_mob,contact_email,designation,contact_add
                    ,contact_phone,contact_fax)
                   VALUES('".$this->Ecnumhid->Value."','".$this->Econtfname1->Text."','".$this->Econtmname1->Text."','".$this->Econtlname1->Text."'
                   ,'".$this->cmbcontmonth1->Items[$this->cmbcontmonth1->ItemIndex]."'
                   ,'".$this->cmbcontday1->Items[$this->cmbcontday1->ItemIndex]."'
                   ,'".$this->cmbcontyear1->Items[$this->cmbcontyear1->ItemIndex]."','".$this->Econtmob1->Text."'
                   ,'".$this->Econtemail1->Text."','".$this->Edesignation1->Text."','".$this->Econtadd1->Text."'
                   ,'".$this->Econtphone1->Text."','".$this->Econtfax1->Text."')")
         or die(mssql_error());
        }
       if($this->Econtfname2->Text != '')
        {
         mssql_query("INSERT INTO contact_tbl(client_num,contact_fname,contact_mname,contact_lname,contactbday_month
                    ,contactbday_day,contactbday_year,contact_mob,contact_email,designation,contact_add
                    ,contact_phone,contact_fax)
                   VALUES('".$this->Ecnumhid->Value."','".$this->Econtfname2->Text."','".$this->Econtmname2->Text."','".$this->Econtlname2->Text."'
                   ,'".$this->cmbcontmonth2->Items[$this->cmbcontmonth2->ItemIndex]."'
                   ,'".$this->cmbcontday2->Items[$this->cmbcontday2->ItemIndex]."'
                   ,'".$this->cmbcontyear2->Items[$this->cmbcontyear2->ItemIndex]."','".$this->Econtmob2->Text."'
                   ,'".$this->Econtemail2->Text."','".$this->Edesignation2->Text."','".$this->Econtadd2->Text."'
                   ,'".$this->Econtphone2->Text."','".$this->Econtfax2->Text."')")
         or die(mssql_error());
        }
        */
        //if($this->Esubfname1->Text != '')
        if($this->saflag->Value == 'new' && $this->sacodehid->Value != "")
        {
         mssql_query("INSERT INTO sub_agent_tbl(sub_code,sub_fname,sub_mname,sub_lname,sub_address
                   ,sub_mobile,sub_email,sub_phone,sub_fax
                   ,subbday_month,subbday_day,subbday_year,sub_region,sub_province,sub_municipal,sub_building)
                   VALUES('".$this->sacodehid->Value."','".$this->Esubfname1->Text."','".$this->Esubmname1->Text."','".$this->Esublname1->Text."'
                   ,'".$this->Esubadd1->Text."'
                   ,'".$this->Esubmobile1->Text."','".$this->Esubemail1->Text."','".$this->Esubphone1->Text."'
                   ,'".$this->Esubfax1->Text."','".$this->cmbsubmonth1->Items[$this->cmbsubmonth1->ItemIndex]."'
                   ,'".$this->cmbsubday1->Items[$this->cmbsubday1->ItemIndex]."'
                   ,'".$this->cmbsubyear1->Items[$this->cmbsubyear1->ItemIndex]."'
                   ,'".$this->saregion->Items[$this->saregion->ItemIndex]."','".$this->editProv3->Value."','".$this->editMun3->Value."','".$this->sabuild->Text."')")
         or die(mssql_error());
        }
        if($this->saflag->Value == 'exist')
        {
         mssql_query("UPDATE sub_agent_tbl SET sub_fname = '".$this->Esubfname1->Text."'
         ,sub_mname = '".$this->Esubmname1->Text."'
         ,sub_lname = '".$this->Esublname1->Text."'
         ,sub_address = '".$this->Esubadd1->Text."'
         ,sub_mobile = '".$this->Esubmobile1->Text."'
         ,sub_email = '".$this->Esubemail1->Text."'
         ,sub_phone = '".$this->Esubphone1->Text."'
         ,sub_fax = '".$this->Esubfax1->Text."'
         ,subbday_month = '".$this->cmbsubmonth1->Items[$this->cmbsubmonth1->ItemIndex]."'
         ,subbday_day = '".$this->cmbsubday1->Items[$this->cmbsubday1->ItemIndex]."'
         ,subbday_year = '".$this->cmbsubyear1->Items[$this->cmbsubyear1->ItemIndex]."'
         ,sub_region = '".$this->saregion->Items[$this->saregion->ItemIndex]."'
         ,sub_province = '".$this->editProv3->Value."'
         ,sub_municipal = '".$this->editMun3->Value."'
         ,sub_building = '".$this->sabuild->Text."' WHERE id = '".$this->said->Value."'") or die(mssql_error());
        }

        $this->Efirstname->Text = "";
        $this->Emiddlename->Text = "";
        $this->Elastname->Text = "";
        $this->Einadd->Text = "";
        $this->cmbRegion->ItemIndex = -1;
        $this->cmbProvince->ItemIndex = -1;
        $this->cmbMunicipal->ItemIndex = -1;
        $this->cmbMonth->ItemIndex = -1;
        $this->cmbday->ItemIndex = -1;
        $this->cmbyear->ItemIndex = -1;
        $this->Einnum->Text = "";
        $this->Einfaxnum->Text = "";
        $this->Einmobile->Text = "";
        $this->Einemail->Text = "";

        $this->Ecompname->Text = "";
        $this->Ecompanyadd->Text = "";
        $this->cmbRegion2->ItemIndex = -1;
        $this->cmbProvince2->ItemIndex = -1;
        $this->cmbMunicipal2->ItemIndex = -1;
        $this->ebusiness->Text = "";
        $this->cmbindust->ItemIndex = -1;
        $this->eproduct->Text = "";
        $this->ephone->Text = "";
        $this->efax->Text = "";
        $this->email->Text = "";

        $this->Econtfname1->Text = "";
        $this->Econtmname1->Text = "";
        $this->Econtlname1->Text = "";
        $this->Econtadd1->Text = "";
        $this->cmbcontmonth1->ItemIndex = -1;
        $this->cmbcontday1->ItemIndex = -1;
        $this->cmbcontyear1->ItemIndex = -1;
        $this->Econtphone1->Text = "";
        $this->Econtfax1->Text = "";
        $this->Econtmob1->Text = "";
        $this->Econtemail1->Text = "";
        $this->Edesignation1->Text = "";

        //$this->Econtfname2->Text = "";
        //$this->Econtmname2->Text = "";
        //$this->Econtlname2->Text = "";
        //$this->Econtadd2->Text = "";
        //$this->cmbcontmonth2->ItemIndex = -1;
        //$this->cmbcontday1->ItemIndex = -1;
        //$this->cmbcontyear2->ItemIndex = -1;
        //$this->Econtphone2->Text = "";
        //$this->Econtfax2->Text = "";
        //$this->Econtmob2->Text = "";
        //$this->Econtemail2->Text = "";
        //$this->Edesignation2->Text = "";

        $this->Esubfname1->Text = "";
        $this->Esubmname1->Text = "";
        $this->Esublname1->Text = "";
        $this->Esubadd1->Text = "";
        $this->cmbsubmonth1->ItemIndex = -1;
        $this->cmbsubday1->ItemIndex = -1;
        $this->cmbsubyear1->ItemIndex = -1;
        $this->Esubphone1->Text = "";
        $this->Esubmobile1->Text = "";
        $this->Esubfax1->Text = "";
        $this->Esubemail1->Text = "";

        redirect("clientlist.php");
        }
       }
       function iclientpageCreate($sender, $params)
       {
        $user = $_SESSION['username'];
        $this->usernamesession->Value = $_SESSION['username'];
        $query = "SELECT * FROM contact_tbl WHERE client_num = '".$user."' ORDER BY date_n DESC";
        $result = mssql_query($query) or die (mssql_error());
        $qcount = mssql_num_rows($result);
        $multi = 165*$qcount;
        //$this->database->Connected = "true";
        //$this->JTIFrame1->height = $multi;
        $this->JTIFrame1->setURL("contactdispedit.php?username=".$user);
        $this->valerror->Value = '0';
        $this->errorlistb->Clear();
        $this->JTDivWindow2->Hide();
        $this->saflag->Value = "new";
        $this->Ecnum->Text = "";
        $this->sabuild->Text = "";
        $this->sacode->Text = "";
        $this->Ecompbldg->Text = "";
        $this->compwebsite->Text = "";
        $this->Ecnumhid->Value = "";
        $this->sacodehid->Value = "";
        $this->cmbday->Clear();
        $this->cmbcontday1->Clear();
        //$this->cmbcontday2->Clear();
        $this->cmbsubday1->Clear();
        $this->Einbldg->Text = "";
        $this->cmbday->AddItem("");
        $this->cmbcontday1->AddItem("");
        //$this->cmbcontday2->AddItem("");
        $this->cmbsubday1->AddItem("");
        $this->cmbRegion->ItemIndex = -1;
        $this->cmbRegion2->ItemIndex = -1;
        $this->saregion->ItemIndex = -1;
        $this->contregion->ItemIndex = -1;

        for($i = 1; $i <= 31; $i++)
         {
          $this->cmbday->AddItem($i);
          $this->cmbcontday1->AddItem($i);
          //$this->cmbcontday2->AddItem($i);
          $this->cmbsubday1->AddItem($i, "", $i);
         }

        $this->cmbyear->Clear();
        $this->cmbcontyear1->Clear();
        //$this->cmbcontyear2->Clear();
        $this->cmbsubyear1->Clear();
        $this->cmbyear->AddItem("");
        $this->cmbcontyear1->AddItem("");
        //$this->cmbcontyear2->AddItem("");
        $this->cmbsubyear1->AddItem("");

        $now = date('Y');
        $this->cmbyear->AddItem(date('Y'));
        $this->cmbcontyear1->AddItem(date('Y'), "", date('Y'));
        //$this->cmbcontyear2->AddItem(date('Y'));
        $this->cmbsubyear1->AddItem(date('Y'), "", date('Y'));

        for($x = 1; $x <= 100; $x++)
         {
          $now = $now - 1;
          $this->cmbyear->AddItem($now);
          $this->cmbcontyear1->AddItem($now, "", $now);
          //$this->cmbcontyear2->AddItem($now);
          $this->cmbsubyear1->AddItem($now, "", $now);

         }
       /*
       $this->Image5->Link = "clientlist.php";
       $this->Image5->LinkTarget = _self;

       $this->lblindi->Link = "iclientpage.php";
       $this->lblcorp->Link = "clientpage.php";
       */
       $query = "SELECT * FROM sub_agent_tbl ORDER BY sub_fname ASC";
       $result = mssql_query($query);
       $num_rows = mssql_num_rows($result);
        if($num_rows > 0)
         {
          $this->subagentcmb->Clear();
          $this->subagentcmb->AddItem("-- Select --", "", "");

          while($row = mssql_fetch_assoc($result))
           {
            $fname = $row['sub_fname'];
            $mname = $row['sub_mname'];
            $lname = $row['sub_lname'];
            $id = $row['id'];
            $fullname = $fname." ".$mname." ".$lname;
            $this->subagentcmb->AddItem($fullname, "", $id);

           }
         }

       $query = "SELECT * FROM region_tbl ORDER BY region ASC";
       $result = mssql_query($query);
       $num_rows = mssql_num_rows($result);
        if($num_rows > 0)
         {
          $this->cmbRegion->Clear();
          $this->cmbRegion2->Clear();
          $this->saregion->Clear();
          $this->contregion->Clear();
          $this->cmbProvince->Clear();
          $this->cmbProvince2->Clear();
          $this->saprov->Clear();
          $this->contprov->Clear();
          $this->cmbMunicipal->Clear();
          $this->cmbMunicipal2->Clear();
          $this->samun->Clear();
          $this->contmun->Clear();

          $this->cmbRegion->AddItem("-- Select --", "", "");
          $this->cmbRegion2->AddItem("-- Select --", "", "");
          $this->saregion->AddItem("-- Select --", "", "");
          $this->contregion->AddItem("-- Select --", "", "");
          $this->cmbProvince->AddItem("-- Select Region First --", "", "");
          $this->cmbProvince2->AddItem("-- Select Region First --", "", "");
          $this->saprov->AddItem("-- Select Region First --", "", "");
          $this->contprov->AddItem("-- Select Region First --", "", "");
          $this->cmbMunicipal->AddItem("-- Select Province First --", "", "");
          $this->cmbMunicipal2->AddItem("-- Select Province First --", "", "");
          $this->samun->AddItem("-- Select Province First --", "", "");
          $this->contmun->AddItem("-- Select Province First --", "", "");

          while($row = mssql_fetch_assoc($result))
           {
            $field1 = $row['region'];

            $this->cmbRegion->AddItem($field1, "", $field1);
            $this->cmbRegion2->AddItem($field1, "", $field1);
            $this->saregion->AddItem($field1, "", $field1);
            $this->contregion->AddItem($field1, "", $field1);
           }
         }



       $query = mssql_query("SELECT * FROM industry_tbl")
       or die (mssql_error());

       $this->cmbindust->Clear();
       $this->cmbindust->AddItem("-- Select --", "", "");

       while ($row = mssql_fetch_assoc($query))
         {
          $field2 = $row[industry];

          $this->cmbindust->AddItem($field2, "", $field2);
         }
       /*
       $query = "SELECT * FROM client_inum_tbl ORDER BY id DESC";
       $result = mssql_query($query);
       $num_rows = mssql_num_rows($result);
       $lastonly = 0;
        if ($num_rows > 0)
         {
         while($row = mssql_fetch_array($result))
          {
           if($lastonly < 1)
           {
           $field = $row[client_num];
           $this->Essrcinum->Text = $field;
           $lastonly = $lastonly + 1;
            }
           }
         }
       $sum = $this->Essrcinum->Text + 1;
       $this->Eclient_num->Text = $sum;

       $this->Eclientnum->Text = $this->Eclient_num->Text;
       mssql_query("INSERT INTO client_inum_tbl (client_num) VALUES ('".$this->Eclient_num->Text."')") or die(mssql_error());
       $this->Ecnum->Text = $this->lblC->Caption.$this->Eclientnum->Text;
       */
       }


}

global $application;

global $iclientpage;

//Creates the form
$iclientpage=new iclientpage($application);

//Read from resource file
$iclientpage->loadResource(__FILE__);

//Shows the form
$iclientpage->show();

?>